<?php
/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
*/

/**
 * Description of Student
 *
 * @author trunghpb
 */
_fwiload::package('SimpleLogic');

function _C($data, &$con, $array) {
    if ($data != null) {
        $con[] = $array;
    }
}
class Student extends SimpleLogic {
    const _MEMBER_STUDENT = 3;

    public function findStudent($condition) {

         $conditions[] = array('','1','=', 1);
        _C($condition['gender'],$conditions,
                array('','member_gender','LIKE', "%{$condition['gender']}%"));
                
        _C($condition['email'],$conditions,
                array('AND','member_email','LIKE', "%{$condition['email']}%"));

        _C($condition['tel1'],$conditions,
                array('AND','member_tel1','LIKE', "%{$condition['tel1']}%"));

        _C($condition['lastName'],$conditions,
                array('AND','member_last_name','LIKE', "%{$condition['lastName']}%"));

        _C($condition['departement'],$conditions,
                array('AND','member_departement_id','=', $condition['departement']));

        $conditions[] = array('AND','member_member_type_id','=', self::_MEMBER_STUDENT);

        _C($condition['orderField'],$conditions,
                array('ORDER BY',"{$condition['orderField']} {$condition['orderDir']}"));

        $this->setTable('member');
        $this->setField(
                array(
                'member_id',
                'member_code',
                'member_family_name',
                'member_middle_name',
                'member_last_name',
                'member_tel1',
                'member_email',
                'member_gender'
        ));
        $this->select($conditions,$result);
        return $result;
    }


}
?>
